package com.mengniu.commerce.sync.api.factory;


import com.mengniu.commerce.sync.api.RemoteMemberService;
import com.mengniu.commerce.sync.api.base.MnResult;
import com.mengniu.commerce.sync.api.domain.MemberInsertModel;
import com.mengniu.commerce.sync.api.domain.MemberModifyModel;
import com.mengniu.commerce.sync.api.domain.MemberRegisterModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 新增会员降级处理
 *
 * @author yz_sm
 */
@Component
public class RemoteMemberFallbackFactory implements FallbackFactory<RemoteMemberService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteMemberFallbackFactory.class);

    @Override
    public RemoteMemberService create(Throwable throwable)
    {
        log.error("数据同步服务--会员--调用失败:{}", throwable.getMessage());
        return new RemoteMemberService()
        {
            @Override
            public MnResult memberInsert(List<MemberInsertModel> list, String source)
            {
                return new MnResult("","存量会员创建失败:" + throwable.getMessage(),false);
            }

            @Override
            public MnResult memberRegister(MemberRegisterModel memberRegisterModel, String source, String userId) {
                return new MnResult("","会员注册失败:" + throwable.getMessage(),false);
            }

            @Override
            public MnResult memberModify(MemberModifyModel memberModifyModel, String source) {
                return new MnResult("","会员更新失败:" + throwable.getMessage(),false);
            }


        };
    }
}
